package com.fary.databinder;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.validation.BindException;
import org.springframework.validation.DataBinder;

import java.util.List;
import java.util.Map;

/**
 * @author Fary
 * @version 1.0
 * @description: TODO
 * @date 2022/2/28 20:13
 */
public class TestDataBinder {

    @Getter
    @Setter
    private Map<String, List<String>> map;

    @Getter
    @Setter
    private String name;
    @Getter
    @Setter
    private int age;
    @Getter
    @Setter
    private TestDataBinder data;


    public static void main(String[] args) throws BindException {
        TestDataBinder bean = new TestDataBinder();
        DataBinder binder = new DataBinder(bean, "bean");
        MutablePropertyValues pvs = new MutablePropertyValues();
//        pvs.add("name", "fsx");
//        pvs.add("age", "18");
//        pvs.add("data.data", new TestDataBinder());
//        pvs.add("data.data.age", "20");
        pvs.add("data.map['key'][0]", "20");

//        binder.setRequiredFields("course");
        binder.bind(pvs);
        Map<?, ?> close = binder.close();

        System.out.println(bean);
        System.out.println(close);
    }
}
